<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>switch</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .bord{
            border: 1px dashed #ee2602;
            width: 90%;
            margin: 20px auto;
        }
        .title{
            font-size: 20px;
            font-weight: bold;
            margin: 20px;
        }
        .introduce{
            font-size: 16px;
            margin: 0 0 20px 50px;
        }
        .red{
            color: red;
        }
    </style>
    <script>
        function myFunction()
        {
            var day=new Date().getDay();
            switch (day)
            {
                case 0:
                    x="Today it's Sunday";
                    break;
                case 1:
                    x="Today it's Monday";
                    break;
                case 2:
                    x="Today it's Tuesday";
                    break;
                case 3:
                    x="Today it's Wednesday";
                    break;
                case 4:
                    x="Today it's Thursday";
                    break;
                case 5:
                    x="Today it's Friday";
                    break;
                case 6:
                    x="Today it's Saturday";
                    break;
            }
            alert(x);
        }
    </script>
</head>
<body>
<div class="bord">
    <div class="title">switch</div>
    <div class="introduce">
        switch 语句用于基于不同的条件来执行不同的动作。<br/>
        <pre>
            switch(n)
                {
                    case 1:
                    执行代码块 1
                    break;

                    case 2:
                    执行代码块 2
                    break;

                    default:
                    n 与 case 1 和 case 2 不同时执行的代码
                }
        </pre>
    </div>
</div>
<div class="bord">
    <div class="title">演示效果</div>
    <div class="introduce">
        <p>点击下面的按钮来显示今天是周几</p><br/>
        <button onclick="myFunction()">点击这里</button>
    </div>
</div>
<div class="bord">
    <div class="title">代码</div>
    <div class="introduce">
        <pre>
        &lt;script&gt;
            function myFunction()
        {
            var day=new Date().getDay();
            switch (day)
            {
                case 0:
                    x="Today it's Sunday";
                    break;
                case 1:
                    x="Today it's Monday";
                    break;
                case 2:
                    x="Today it's Tuesday";
                    break;
                case 3:
                    x="Today it's Wednesday";
                    break;
                case 4:
                    x="Today it's Thursday";
                    break;
                case 5:
                    x="Today it's Friday";
                    break;
                case 6:
                    x="Today it's Saturday";
                    break;
            }
            alert(x);
        }
        &lt;/script&gt;

        &lt;p&gt;点击下面的按钮来显示今天是周几&lt;/p&gt;
        &lt;button onclick="myFunction()"&gt;点击这里&lt;/button&gt;
            </pre>
    </div>
</div>
</body>
</html>